from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated
# Create your views here.
from coupon.services import get_user_coupon_list,get_user_enable_coupon_list
from fuguang.utils import constants
class CouponListView(APIView):
    permission_classes = [IsAuthenticated]
    def get(self, request):
        user_id = request.user.id
        coupon_list = get_user_coupon_list(user_id)
        return Response({"message":"优惠券列表获取成功","coupon":coupon_list})


class EnableCouponListView(APIView):
    permission_classes = [IsAuthenticated]
    def get(self, request):
        user_id = request.user.id
        data = get_user_enable_coupon_list(user_id)
        return Response({"message":"可用的优惠券列表获取成功",
                         "coupon_list":data,
                         "has_credit":request.user.credit,
                         "credit_to_money":constants.CREDIT_TO_MONEY
                         })

